package com.jn.news.net;

import com.jn.news.model.JuheNews;
import com.jn.news.model.MedicineSearch;
import com.jn.news.model.News;
import com.jn.news.model.NewsClassify;
import com.jn.news.model.RespDto;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.disposables.CompositeDisposable;

public class HttpRequestUtils {
    private final ApiService juheService;
    private ApiService tianxingService;
    private CompositeDisposable disposable = new CompositeDisposable();
    private String tianxingKey = "f7006581bddec5cb32e35c7e698210af";
    private String juheKey = "a1a1d9ddd8f4d48931f6adf49976c66b";
    private static final String BASE_URL = "https://apis.tianapi.com/";
    private static final String JUHE_BASE_URL = "http://v.juhe.cn/";

    public HttpRequestUtils() {
        this.tianxingService = RetrofitClient.getInstance(BASE_URL).getApiService();
        juheService = RetrofitClient.getInstance(JUHE_BASE_URL).getApiService();
    }
    public Observable<RespDto<NewsClassify>> getNewsClassify() {
        return tianxingService.getNewsClassify(tianxingKey);
    }
    public Observable<RespDto<News>> getNewsList(int col,int pageSize,int pageNum) {
        return tianxingService.getNews(tianxingKey,col,pageSize,pageNum);
    }
    public Observable<RespDto<MedicineSearch>> queryMedicine(String medicine) {
        return tianxingService.queryMedicine(tianxingKey,medicine);
    }
    public Observable<RespDto<JuheNews>> getJuheNews(String type,int pageNum,int pageSize) {
        return juheService.getJuheNews(juheKey,type,pageNum,pageSize,1);
    }

    public void dispose() {
        disposable.clear();
    }
}
